var app = getApp();

var pageData = {
    data: {
      defaultSize: 'default',
      primarySize: 'default',
      warnSize: 'default',
      disabled: false,
      plain: false,
      loading: false,
      text_val:'',
      userIbfo:{
        pass_number:"",
        pass_problem:'',
        pass_Answer:'',
        pass_newpass:''
      },
      phone_flag: ''     //phone  如果 从 个人中心点击进来就 触发                                ,
    },
    onLoad: function (e) {
      // console.log(e.Route)
    switch(e.Route){
      case "My":
      this.setData({
        phone_flag:'phone',
      });
      this.data.userIbfo.pass_number = '15281175682';
      this.pass_problem();
      break;
      case "login":

        break;
    };
           
    },
    onShow: function (e) {
      // console.log(e)
      // this.setData({
      //   UserName: app.globalData.UserInfo.nickname,
      //   UserPhone: app.globalData.UserInfo.phone,
      //   addressValue: app.globalData.UserInfo.userinfo.address
      // });
    },
    pass_number(e){  //账号
      if (e.detail.value.length == 11){
        this.data.userIbfo.pass_number = e.detail.value;
        this.pass_problem();
      }
    },
    pass_problem(){  //密保问题
      var url = app.globalData.HOST + app.APILIST.resetPassword;
      var data = {
        "data": {
          "phone": this.data.userIbfo.pass_number
        }
      };
      app.WxRequest(url, data, 1,
        (res) => {
          if (res.status_code == 200) {
            this.setData({
              userIbfo: {
                pass_problem: res.data.ask
              }
            });
          }
        }, (ref) => {
        });
    },
    pass_Answer(e){  //密保
      this.data.userIbfo.pass_Answer = e.detail.value
    
    },
    pass_newpass(e){  //新密码
      this.data.userIbfo.pass_newpass = e.detail.value
    },
  warn(e){ //提交 更新的地址
    this.setData({
      loading:true
    });
    var url = app.globalData.HOST + app.APILIST.resetPassword;
    var data = {
      "data": {
        "phone": this.data.userIbfo.pass_number,
        "answer": this.data.userIbfo.pass_Answer,
        'newpassword': this.data.userIbfo.pass_newpass
      }
    };
    app.WxRequest(url,data, 1,
      (res) => {
 
        if(res){
          switch (res.status_code){
            case 200:
              wx.showToast({
                title: '修改成功',
                image: '/images/dui.png',
                duration: 1000
              });
            break;
            case 500:
              wx.showToast({
                title: res.Massage,
                image: '/images/cuo.png',
                duration: 1000
              });
            break;
          }
        }
        this.setData({
          loading: false
        });
      }, (ref) => {
      });

  },


  model_address(e){  //获取 地址的值
    this.data.text_val = e.detail.value;
    // console.log(e.detail.value)
  }

};
Page(pageData);
